package com.teamone.etl.apimanager.entity;

import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.teamone.etl.apimanager.valid.AddGroup;
import com.teamone.etl.apimanager.valid.UpdateGroup;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Transient;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import java.io.Serializable;
import java.util.Date;

/**
 * 源接口表(ApiSource)表实体类
 *
 * @author makejava
 * @since 2021-01-20 18:32:05
 */
@EqualsAndHashCode(callSuper = true)
@SuppressWarnings("serial")
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ApiSource extends Model<ApiSource> {
    /**序号
     *
     */
    @NotNull(message = "接口Id不能为空",groups = {UpdateGroup.class})
    private Integer id;

    /**接口名称
     *
     */
    @NotEmpty(message = "接口名称不能为空",groups = {AddGroup.class,UpdateGroup.class})
    private String name;

    /**接口描述
     *
     */
    @NotEmpty(message = "接口描述不能为空",groups = {AddGroup.class,UpdateGroup.class})
    private String description;

    /**接口图片
     *
     */
    @NotEmpty(message = "接口图片不能为空",groups = {AddGroup.class,UpdateGroup.class})
    private String pictureUrl;

    /**简介
     *
     */
    @NotEmpty(message = "接口简介不能为空",groups = {AddGroup.class,UpdateGroup.class})
    private String briefIntroduction;

    /**创建时间
     *
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy/M/d",timezone = "GMT+8")
    private Date createTime;

    /**创建人
     *
     */
    private String createBy;

    /**更新时间
     *
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy/M/d",timezone = "GMT+8")
    private Date updateTime;

    /**修改人
     *
     */
    private String updateBy;

    /**接口类型id
     *
     */
    @NotNull(message = "接口类型id不能为空",groups = {AddGroup.class,UpdateGroup.class})
    private Integer apiTypeId;

    /**计费类型
     *
     */
    private Integer chargeMethod;

    /**请求方式
     *
     */
    @NotEmpty(message = "请求方式不能为空",groups = {AddGroup.class,UpdateGroup.class})
    private String requestMethod;

    /**请求地址
     *
     */
    @NotEmpty(message = "请求地址不能为空",groups = {AddGroup.class,UpdateGroup.class})
    private String requestUrl;

    /**请求示例
     *
     */
    @NotEmpty(message = "请求示例不能为空",groups = {AddGroup.class,UpdateGroup.class})
    private String requestExample;

    /**返回格式，1JSON，2XML
     *
     */
    @NotNull(message = "返回格式不能为空",groups = {AddGroup.class,UpdateGroup.class})
    private Integer returnFormat;

    /**JSON返回示例
     *
     */
    @NotEmpty(message = "JSON返回示例不能为空",groups = {AddGroup.class,UpdateGroup.class})
    private String jsonExample;

    /**XML返回示例
     *
     */
    @NotEmpty(message = "xml返回示例不能为空",groups = {AddGroup.class,UpdateGroup.class})
    private String xmlExample;

    /**请求参数说明
     *
     */
    @NotEmpty(message = "请求参数说明不能为空",groups = {AddGroup.class,UpdateGroup.class})
    private String requestParam;

    /**返回参数说明
     *
     */
    @NotEmpty(message = "返回参数说明不能为空",groups = {AddGroup.class,UpdateGroup.class})
    private String returnParam;

    /**
     * 逻辑删除
     */
    private Boolean isDelete;

    /**
     * 接口使用量
     */
    private Integer useAmount;

    /**
     * 接口来源
     */
    @NotEmpty(message = "接口来源不能为空",groups = {AddGroup.class})
    private String source;

    /**
     * 收费方式
     */
    @Transient
    private Integer chargeType;
    /**
     * 次数
     */
    @Transient
    private Integer count;
    /**
     * 天数
     */
    @Transient
    private Integer days;
    /**
     * 价格
     */
    @Transient
    private Integer price;

    /**
     * 获取主键值
     *
     * @return 主键值
     */
    @Override
    protected Serializable pkVal() {
        return this.id;
    }

    public void setApiCharge(ApiCharge apiCharge) {
        this.chargeType=apiCharge.getChargeType();
        this.count=apiCharge.getCount();
        this.days=apiCharge.getDays();
        this.price=apiCharge.getPrice();
    }
}